package cn.ffcs.uec.salary.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Tab;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.portal.theme.ThemeDisplay;
import cn.ffcs.uec.salary.action.bean.UecSalaryMainBean;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.UomZkUtil;

@Controller
@Scope("prototype")
public class UecSalaryMainComposer extends BasePortletComposer implements IPortletInfoProvider{
	private static final long serialVersionUID = -39915854935618809L;
	
	private UecSalaryMainBean bean = new UecSalaryMainBean();
	
	@Override
	public String getPortletId() {
		return super.getPortletId();
	}
	
	@Override
	public ThemeDisplay getThemeDisplay() {
		return super.getThemeDisplay();
	}
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		UomZkUtil.autoFitHeight(comp);
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);
		this.bean.getUecSalaryPiListboxExt().setPortletInfoProvider(this);
		this.bean.getUecSalaryPrjListboxExt().setPortletInfoProvider(this);
		this.bean.getUecSalaryPlanListboxExt().setPortletInfoProvider(this);
	}
	
	/**
	 * 点击tab
	 * 
	 * @throws Exception
	 */
	public void onClickTab(ForwardEvent forwardEvent) throws Exception {
		Event event = forwardEvent.getOrigin();
		if (event != null) {
			Component component = event.getTarget();
			if (component != null && component instanceof Tab) {
				final Tab clickTab = (Tab) component;
				bean.setSelectTab(clickTab);
				
				if (this.bean.getSelectTab() == null) {
					bean.setSelectTab(this.bean.getTabBox().getSelectedTab());
				}
			}
		}
	}
}
